/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package edu.pku.sei.ocl.cst.impl;

import edu.pku.sei.ocl.cst.CSTPackage;
import edu.pku.sei.ocl.cst.HelperCallExpCS;
import edu.pku.sei.ocl.cst.OCLExpressionCS;
import edu.pku.sei.ocl.cst.SimpleNameCS;
import edu.pku.sei.ocl.evaluation.Context;
import edu.pku.sei.ocl.visitor.AbstractOCLVisitor;

import java.util.Map;
import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Helper Call Exp CS</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link edu.pku.sei.ocl.cst.impl.HelperCallExpCSImpl#getHelperName <em>Helper Name</em>}</li>
 *   <li>{@link edu.pku.sei.ocl.cst.impl.HelperCallExpCSImpl#isDefaultAM <em>Default AM</em>}</li>
 *   <li>{@link edu.pku.sei.ocl.cst.impl.HelperCallExpCSImpl#getArguments <em>Arguments</em>}</li>
 *   <li>{@link edu.pku.sei.ocl.cst.impl.HelperCallExpCSImpl#getFpNames <em>Fp Names</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class HelperCallExpCSImpl extends OCLExpressionCSImpl implements
		HelperCallExpCS {
	/**
	 * The cached value of the '{@link #getHelperName() <em>Helper Name</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getHelperName()
	 * @generated
	 * @ordered
	 */
	protected SimpleNameCS helperName;

	/**
	 * The default value of the '{@link #isDefaultAM() <em>Default AM</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isDefaultAM()
	 * @generated
	 * @ordered
	 */
	protected static final boolean DEFAULT_AM_EDEFAULT = false;

	/**
	 * The flag representing the value of the '{@link #isDefaultAM() <em>Default AM</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isDefaultAM()
	 * @generated
	 * @ordered
	 */
	protected static final int DEFAULT_AM_EFLAG = 1 << 8;

	/**
	 * The cached value of the '{@link #getArguments() <em>Arguments</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getArguments()
	 * @generated
	 * @ordered
	 */
	protected EList<OCLExpressionCS> arguments;

	/**
	 * The cached value of the '{@link #getFpNames() <em>Fp Names</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getFpNames()
	 * @generated
	 * @ordered
	 */
	protected EList<SimpleNameCS> fpNames;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected HelperCallExpCSImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return CSTPackage.Literals.HELPER_CALL_EXP_CS;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public SimpleNameCS getHelperName() {
		return helperName;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetHelperName(SimpleNameCS newHelperName,
			NotificationChain msgs) {
		SimpleNameCS oldHelperName = helperName;
		helperName = newHelperName;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this,
					Notification.SET,
					CSTPackage.HELPER_CALL_EXP_CS__HELPER_NAME, oldHelperName,
					newHelperName);
			if (msgs == null)
				msgs = notification;
			else
				msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setHelperName(SimpleNameCS newHelperName) {
		if (newHelperName != helperName) {
			NotificationChain msgs = null;
			if (helperName != null)
				msgs = ((InternalEObject) helperName).eInverseRemove(this,
						EOPPOSITE_FEATURE_BASE
								- CSTPackage.HELPER_CALL_EXP_CS__HELPER_NAME,
						null, msgs);
			if (newHelperName != null)
				msgs = ((InternalEObject) newHelperName).eInverseAdd(this,
						EOPPOSITE_FEATURE_BASE
								- CSTPackage.HELPER_CALL_EXP_CS__HELPER_NAME,
						null, msgs);
			msgs = basicSetHelperName(newHelperName, msgs);
			if (msgs != null)
				msgs.dispatch();
		} else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					CSTPackage.HELPER_CALL_EXP_CS__HELPER_NAME, newHelperName,
					newHelperName));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isDefaultAM() {
		return (eFlags & DEFAULT_AM_EFLAG) != 0;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setDefaultAM(boolean newDefaultAM) {
		boolean oldDefaultAM = (eFlags & DEFAULT_AM_EFLAG) != 0;
		if (newDefaultAM)
			eFlags |= DEFAULT_AM_EFLAG;
		else
			eFlags &= ~DEFAULT_AM_EFLAG;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					CSTPackage.HELPER_CALL_EXP_CS__DEFAULT_AM, oldDefaultAM,
					newDefaultAM));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<OCLExpressionCS> getArguments() {
		if (arguments == null) {
			arguments = new EObjectContainmentEList<OCLExpressionCS>(
					OCLExpressionCS.class, this,
					CSTPackage.HELPER_CALL_EXP_CS__ARGUMENTS);
		}
		return arguments;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<SimpleNameCS> getFpNames() {
		if (fpNames == null) {
			fpNames = new EObjectContainmentEList<SimpleNameCS>(
					SimpleNameCS.class, this,
					CSTPackage.HELPER_CALL_EXP_CS__FP_NAMES);
		}
		return fpNames;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd,
			int featureID, NotificationChain msgs) {
		switch (featureID) {
		case CSTPackage.HELPER_CALL_EXP_CS__HELPER_NAME:
			return basicSetHelperName(null, msgs);
		case CSTPackage.HELPER_CALL_EXP_CS__ARGUMENTS:
			return ((InternalEList<?>) getArguments()).basicRemove(otherEnd,
					msgs);
		case CSTPackage.HELPER_CALL_EXP_CS__FP_NAMES:
			return ((InternalEList<?>) getFpNames())
					.basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
		case CSTPackage.HELPER_CALL_EXP_CS__HELPER_NAME:
			return getHelperName();
		case CSTPackage.HELPER_CALL_EXP_CS__DEFAULT_AM:
			return isDefaultAM();
		case CSTPackage.HELPER_CALL_EXP_CS__ARGUMENTS:
			return getArguments();
		case CSTPackage.HELPER_CALL_EXP_CS__FP_NAMES:
			return getFpNames();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
		case CSTPackage.HELPER_CALL_EXP_CS__HELPER_NAME:
			setHelperName((SimpleNameCS) newValue);
			return;
		case CSTPackage.HELPER_CALL_EXP_CS__DEFAULT_AM:
			setDefaultAM((Boolean) newValue);
			return;
		case CSTPackage.HELPER_CALL_EXP_CS__ARGUMENTS:
			getArguments().clear();
			getArguments().addAll(
					(Collection<? extends OCLExpressionCS>) newValue);
			return;
		case CSTPackage.HELPER_CALL_EXP_CS__FP_NAMES:
			getFpNames().clear();
			getFpNames().addAll((Collection<? extends SimpleNameCS>) newValue);
			return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
		case CSTPackage.HELPER_CALL_EXP_CS__HELPER_NAME:
			setHelperName((SimpleNameCS) null);
			return;
		case CSTPackage.HELPER_CALL_EXP_CS__DEFAULT_AM:
			setDefaultAM(DEFAULT_AM_EDEFAULT);
			return;
		case CSTPackage.HELPER_CALL_EXP_CS__ARGUMENTS:
			getArguments().clear();
			return;
		case CSTPackage.HELPER_CALL_EXP_CS__FP_NAMES:
			getFpNames().clear();
			return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
		case CSTPackage.HELPER_CALL_EXP_CS__HELPER_NAME:
			return helperName != null;
		case CSTPackage.HELPER_CALL_EXP_CS__DEFAULT_AM:
			return ((eFlags & DEFAULT_AM_EFLAG) != 0) != DEFAULT_AM_EDEFAULT;
		case CSTPackage.HELPER_CALL_EXP_CS__ARGUMENTS:
			return arguments != null && !arguments.isEmpty();
		case CSTPackage.HELPER_CALL_EXP_CS__FP_NAMES:
			return fpNames != null && !fpNames.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy())
			return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (defaultAM: "); //$NON-NLS-1$
		result.append((eFlags & DEFAULT_AM_EFLAG) != 0);
		result.append(')');
		return result.toString();
	}

	@Override
	public Object accept(AbstractOCLVisitor v, Context env, Object... argv) {
		if (argv == null || argv.length == 0) {
			return v.visitHelperCallExpCS(this, env);
		} else {
			return v.visitHelperCallExpCS(this, env, argv);
		}
	}
} //HelperCallExpCSImpl
